{% extends "layout.html" %}

{% block head %}
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
<script src="{{ url_for('static', filename='lib/html5.min.js') }}"></script>
<script src="{{ url_for('static', filename='lib/respond.min.js') }}"></script>
<![endif]-->
{% endblock %}

{% block body %}
    <div class="x-body">
        <xblock>
            <button class="layui-btn" onclick="x_admin_show('添加账号','')"><i
                    class="layui-icon"></i>添加账号
            </button>
            <span class="x-right" style="line-height:40px">共有数据：{{ count }} 条</span>
        </xblock>
        <table class="layui-table">
            <thead>
            <tr>
                <th>
                    <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                            class="layui-icon">&#xe605;</i></div>
                </th>
                <th>id</th>
                <th>username</th>
                <th>password</th>
                <th>info</th>
                <th>操作</th>
            </thead>
            <tbody>
            {% for account in accounts %}
                <tr>
                    <td>
                        <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i
                                class="layui-icon">&#xe605;</i>
                        </div>
                    </td>
                    <td>{{ account.id }}</td>
                    <td>{{ account.username }}</td>
                    <td>{{ account.password }}</td>
                    <td> info... </td>
                    <td class="td-manage">
                        <a title="删除" onclick="account_del(this,'{{ url_for('account_op', _id=account.id) }}')"
                           href="javascript:;">
                            <i class="layui-icon">&#xe640;</i>
                        </a>
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>

    <script>
        /*账号-删除*/
        function account_del(obj, url) {
            layer.confirm('确认要删除吗？', function (index) {
                $.ajax({
                    url: url,
                    type: "delete",
                    success: function (msg) {
                        if (msg.flag != 'success') {
                            layer.msg(msg.msg, {icon: 2});
                        } else {
                            $(obj).parents("tr").remove();
                            layer.msg('已删除!', {icon: 1});
                        }
                    }, error: function () {
                        layer.msg('删除异常！', {icon: 2});
                    }
                });
            });
        }

    </script>
{% endblock %}
